<?php

class Settings_Model extends Model {

	function Settings_Model()
	{
		parent::Model(); 
	}
	
	//todo: optimize
	function get_options() {
		
		$query = $this->db->query('SELECT * FROM options');
		$results = $query->result();
		
		foreach ($results as $result) {			
			$options->{$result->option} = $result->value;			
		}
		
		return $options;
	}
	
	//todo: optimize
	function set_options($options) {
		//we can validate here
		$this->db->where('id', 1);
		$this->db->update('options', $options);
		
		return true;
	}
	
	//todo: optimize
	function get_themes() {
		//return a list of theme names
		$query = $this->db->get('themes');
		$results = $query->result();
		return $results;
	}
	
	function get_theme() {
		$this->db->where('option', 'theme');
		$this->db->select('value');
		$query = $this->db->get('options');
		$results = $query->result();
		return $results[0]->value;
	}
	
	//todo: optimize
	function install_theme($themename) {
		//add the theme's name to the database
		//a folder named $themename must exist in the /themes/ directory
		//and there must be (at least) the following files in it:
		//category.php
		//index.php
		//item.php
		//page.php
		$this->db->insert('themes', array('name' => '$themename'));
	}
	
	//todo: optimize
	function delete_theme($themename) {
		//remove the theme name from the database. this does not
		//remove the folder from /themes/. you'll have to do that
		//manually, or just ignore it
		$this->db->delete('table_name', array('name', $themename));
	}


	
}
?>